import * as THREE from 'three';
class Map {
    constructor(Meteor3D) {
        this.Meteor3D = Meteor3D
        this.geoBounds = {
            minLon: 104.055633544921875,
            maxLon: 104.069366455078125,
            minLat: 30.550435135095270,
            maxLat: 30.561078433806014,
        };

        this.imgWidth = 2560;
        this.imgHeight = 2304;

        this.planeWidth = this.imgWidth;
        this.planeHeight = this.imgHeight;


        this.lonRange = this.geoBounds.maxLon - this.geoBounds.minLon;
        this.latRange = this.geoBounds.maxLat - this.geoBounds.minLat;

        this.mapPlane = null
    }
    lonLatToPlane(lon, lat) {
        const x = ((lon - this.geoBounds.minLon) / this.lonRange - 0.5) * this.planeWidth;
        const y = ((lat - this.geoBounds.minLat) / this.latRange - 0.5) * this.planeHeight;
        return new THREE.Vector3(x, 0, -y); // Y轴朝上，所以取负
    }
    add(){
        const texture = new THREE.TextureLoader().load('/assets/images/55.png', () => {
            // renderer.render(scene, camera);
        });

        // ---------------------------------
        // 创建平面贴图
        // ---------------------------------
        const planeGeo = new THREE.PlaneGeometry(this.planeWidth, this.planeHeight);
        const planeMat = new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide });
        this.mapPlane = new THREE.Mesh(planeGeo, planeMat);
        this.mapPlane.isMap = true
        this.mapPlane.rotation.x = -Math.PI / 2
        this.mapPlane.name = '地图'
        this.Meteor3D.scene.add(this.mapPlane);
    }
    remove(){
        this.Meteor3D.scene.remove(this.mapPlane)
    }
}

export default Map;